package VN.EDU.IMIC.DEVELOPER.TRANTHITHANHNGA.EXJSON;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.border.TitledBorder;
import javax.swing.UIManager;
import java.awt.Color;
import javax.swing.event.AncestorListener;
import javax.swing.event.AncestorEvent;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.ContainerAdapter;
import java.awt.event.ContainerEvent;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JComboBox;
import javax.swing.JList;
import javax.swing.AbstractListModel;
import javax.swing.ListSelectionModel;

public class Studenttable extends JFrame {

	private JPanel contentPane;
	private JTextField txtRollNo;
	private JTextField txtFullName;
	private JTextField txtPhone;
	private JTextField txtEmail;
	private JTextField txtMark;
	private JTextField txtClass;
	private int iCount;
	List<Students> StudentList = new ArrayList<>();

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Studenttable frame = new Studenttable();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});

	}

	/**
	 * Create the frame.
	 */
	public Studenttable() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 657, 341);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);

		txtRollNo = new JTextField();
		txtRollNo.setBounds(165, 29, 86, 14);
		contentPane.add(txtRollNo);
		txtRollNo.setColumns(10);

		JLabel lblRollno = new JLabel("RollNo");
		lblRollno.setBounds(56, 29, 46, 14);
		contentPane.add(lblRollno);

		JLabel lblFullname = new JLabel("FullName");
		lblFullname.setBounds(56, 60, 46, 14);
		contentPane.add(lblFullname);

		txtFullName = new JTextField();
		txtFullName.setBounds(165, 60, 308, 14);
		contentPane.add(txtFullName);
		txtFullName.setColumns(10);

		JLabel lblPhone = new JLabel("Phone");
		lblPhone.setBounds(56, 85, 46, 14);
		contentPane.add(lblPhone);

		txtPhone = new JTextField();
		txtPhone.setBounds(165, 85, 142, 14);
		contentPane.add(txtPhone);
		txtPhone.setColumns(10);

		txtEmail = new JTextField();
		txtEmail.setBounds(165, 110, 135, 14);
		contentPane.add(txtEmail);
		txtEmail.setColumns(10);

		txtMark = new JTextField();
		txtMark.setBounds(165, 135, 86, 14);
		contentPane.add(txtMark);
		txtMark.setColumns(10);

		JLabel lblClass = new JLabel("Email");
		lblClass.setBounds(56, 110, 46, 14);
		contentPane.add(lblClass);

		JLabel lblMark = new JLabel("Mark");
		lblMark.setBounds(56, 135, 46, 14);
		contentPane.add(lblMark);

		JButton btnAdd = new JButton("Add");
		btnAdd.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				Choice objChoice = new Choice(StudentList);
				objChoice.setVisible(true);
			}
		});

		btnAdd.setBounds(148, 201, 89, 23);
		contentPane.add(btnAdd);

		JButton btnUpdate = new JButton("Update");

		btnUpdate.setBounds(279, 201, 89, 23);
		contentPane.add(btnUpdate);

		JButton btnCancel = new JButton("Cancel");
		btnCancel.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				System.exit(0);
			}
		});
		btnCancel.setBounds(406, 201, 89, 23);
		contentPane.add(btnCancel);

		JLabel lblClasstype = new JLabel("Class");
		lblClasstype.setBounds(56, 160, 46, 14);
		contentPane.add(lblClasstype);

		txtClass = new JTextField();
		txtClass.setBounds(165, 157, 86, 20);
		contentPane.add(txtClass);
		txtClass.setColumns(10);
		
		JButton btnNewButton = new JButton("Addinfo");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				iCount++;
				Students objSV = new Students();
				objSV.setId(iCount);
				objSV.setRollNo(Integer.parseInt(""+ txtRollNo.getText()));
				objSV.setFullName(""+txtFullName.getText());
				objSV.setPhone(""+txtPhone.getText());
				objSV.setEmail(""+txtEmail.getText());
				objSV.setMark(Double.parseDouble(""+txtMark.getText()));
				objSV.setClassNo(""+txtClass.getText());
				StudentList.add(objSV);
				
				txtRollNo.setText("");
				txtFullName.setText("");
				txtPhone.setText("");
				txtEmail.setText("");
				txtMark.setText("");
				txtClass.setText("");
				
			}
		});
		btnNewButton.setBounds(532, 201, 99, 23);
		contentPane.add(btnNewButton);

	}
}
